package com.shop.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.shop.constant.MessageConstant;
import com.shop.entity.Result;
import com.shop.pojo.Goods;
import com.shop.service.GoodsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/goods")
@Api(tags = "商品管理")
public class GoodsController {
    @Reference
    private GoodsService goodsService;

    @GetMapping("/goodspage")
    @ApiOperation("商品分页接口")
    @ApiImplicitParams({@ApiImplicitParam(dataType = "int",name = "gid",value = "商品分类id",required = true,example = "0"),@ApiImplicitParam(dataType = "int",name = "pagenum",value = "页数",required = true,example = "0"),@ApiImplicitParam(dataType = "int",name = "pagesize",value = "每页显示条数",required = true,example = "0")})
    private Result findProduct(@RequestParam(value = "gid",required = true) Integer gid,
                               @RequestParam(value = "currentPage",required = true) Integer pagenum,
                               @RequestParam(value = "pageSize",required = true) Integer pagesize){
        Page<Goods> page = goodsService.goodsPage(gid,pagenum,pagesize);
        return new Result(true, MessageConstant.QUERY_GOODS_SUCCESS,page);
    }

    @GetMapping("/getgoods")
    @ApiOperation("商品详情接口")
    @ApiImplicitParams({@ApiImplicitParam(dataType = "int",name = "id",value = "商品分类id",required = true,example = "0")})
    private Result getGoods(@RequestParam(required = true) Integer id){
        Goods goods= goodsService.getGoods(id);
        return new Result(true,MessageConstant.QUERY_GOODS_SUCCESS,goods);
    }
}
